package com.zryc.shop.oms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.oms.entity.OrderReturnReason;
import com.zryc.shop.oms.service.IOrderReturnReasonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

/**
 * <p>
 * 退货原因表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "退货原因管理")
@RequestMapping("/oms/returnReason")
public class OrderReturnReasonController {

    @Autowired
    private IOrderReturnReasonService orderReturnReasonService;

    @GetMapping("/list")
    @ApiOperation("分页查询列表")
    public Result list(@RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页显示条数", required = true) Integer pageSize){
        return Result.ok(orderReturnReasonService.list(pageNum, pageSize));
    }

    @PostMapping("/update/status")
    @ApiOperation("修改状态")
    public Result updateStatus(@RequestParam String ids, Integer status){
        return Result.ok(orderReturnReasonService.updateStatus(ids,status));
    }

    @PostMapping("/create")
    @ApiOperation("添加退货原因")
    public Result create(@RequestBody OrderReturnReason returnReason){
        returnReason.setCreateTime(LocalDateTime.now());
        return Result.ok(orderReturnReasonService.save(returnReason));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询详情")
    public Result info(@PathVariable Long id){
        return Result.ok(orderReturnReasonService.getById(id));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("修改退货原因")
    public Result update(@PathVariable Long id, @RequestBody OrderReturnReason returnReason){
        return Result.ok(orderReturnReasonService.detail(id,returnReason));
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public Result delete(@RequestParam String ids){
        String[] idList=ids.split(",");
        return  Result.ok(orderReturnReasonService.removeBatchByIds(Arrays.asList(idList)));
    }

}
